/*******************************************************************************
 * Copyright (c) 2008, 2009 Tapestry IDE Developers
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Tapestry IDE Developers - initial API and implementation
 *******************************************************************************/
package com.googlecode.tapestry.ide.core;

import org.eclipse.core.resources.IResource;

/**
 * The Enum TapestryFileType.
 */
public enum TapestryFileType {

	/** Java. */
	JAVA("java"),

	/** Tapestry Template. */
	TML("tml"),

	/** Unknown. */
	NULL("");

	/** The extension. */
	private String extension;

	/**
	 * Instantiates a new tapestry file type.
	 * 
	 * @param extension
	 *            the extension
	 */
	private TapestryFileType(String extension) {
		this.extension = extension;
	}

	/**
	 * Gets the extension.
	 * 
	 * @return the extension
	 */
	public String getExtension() {
		return extension;
	}

	/**
	 * From extension.
	 * 
	 * @param extension
	 *            the extension
	 * 
	 * @return the tapestry file type
	 */
	public static TapestryFileType fromExtension(String extension) {
		for (TapestryFileType type : values()) {
			if (type.extension.equals(extension)) {
				return type;
			}
		}
		return NULL;
	}

	/**
	 * From resource.
	 * 
	 * @param resource
	 *            the resource
	 * 
	 * @return the tapestry file type
	 */
	public static TapestryFileType fromResource(IResource resource) {
		return fromExtension(resource.getFileExtension());
	}

}
